package com.czh.controller;

import com.czh.domain.ResponseResult;
import com.czh.domain.dto.QueryArticleDto;
import com.czh.domain.entity.Article;
import com.czh.domain.vo.ArticleManageDetailVo;
import com.czh.domain.vo.ArticleManageVo;
import com.czh.domain.vo.ArticlePageVo;
import com.czh.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 文章管理控制器
 */
@RestController
@RequestMapping("/content/article")
public class ArticleManageController {
    @Autowired
    private ArticleService articleService;
    //文章列表
    @GetMapping("/list")
    public ResponseResult<ArticlePageVo<ArticleManageVo>> getArticleList(Integer pageNum, Integer pageSize,
                                                                          QueryArticleDto queryArticleDto){
        return articleService.pageArticleList(pageNum,pageSize, queryArticleDto);
    }
    //修改文章时填充文章详情
    @GetMapping("/{id}")
    public ResponseResult<ArticleManageDetailVo> ArticleDetDetail(@PathVariable("id") Long id){
        return articleService.getArticleManageDetail(id);
    }
    @DeleteMapping("/{id}")
    public ResponseResult<Object> deleteArticle(@PathVariable("id") Long id){
        return articleService.deleteArticle(id);
    }
    @PutMapping
    public ResponseResult<Object> updateArticle(@RequestBody Article article){
        return articleService.updateArticle(article);
    }
}
